#include <algorithm>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <istream>
#include <set>
#include <string>
using ll = int64_t;
#define sl static inline

ll n,op,res,now,nres;
char tmp;
std::string st;
std::set<char> used;
bool iserror;
struct S{
    char c;
    ll res;
    bool isok;
};
std::deque<S> stk;
#define printf
sl void solve(){
    op=0,res=0;
    iserror=false;
    used.clear();
    stk.clear();
    std::cin>>tmp>>tmp>>tmp;
    if(tmp=='1'){
        op=0;
        std::cin>>tmp;
    }else{
        std::cin>>tmp;
        std::cin>>op;
        std::cin>>tmp;
    }
    printf("STARTING %lld Get O(n^%lld)\n",++now,op);
    while(std::cin>>st){
        printf("while st=%s\n",st.data());
        ll add=0;
        if(st=="F"){
            char i;
            bool isok=(stk.size()?stk.back().isok:true);
            std::string x,y;
            std::cin>>i>>x>>y;
            if(y=="n"&&x!="n"){
                add++;
            }else if(x=="n"&&isdigit(y[0])){
                isok=false;
            }else if(isdigit(x[0])&&isdigit(y[0])){
                ll nx=atoi(x.data()),ny=atoi(y.data());
                if(nx>ny){
                    isok=false;
                }
            }
            if(used.find(i)!=used.end()){
                iserror=true;
            }else{
                used.emplace(i);
            }
            stk.push_back({i,stk.empty()?add:stk.back().res+add,isok});
        }else if(st=="E"){
            if(stk.empty()){
                iserror=true;
            }else{
                printf("pop stk c=%c, res=%lld\n",stk.back().c,stk.back().res);
                if(stk.back().isok){
                    res=std::max(res,stk.back().res);
                }
                used.erase(stk.back().c);
                stk.pop_back();
            }
        }else{
            n=atoi(st.data());
            break;
        }
    }
    if(stk.size())iserror=true;
    if(iserror){
        std::cout<<"ERR\n";
    }else{
        std::cout<<(res==op?"Yes":"No")<<"\n";
    }
}

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll t;
    std::cin>>t;
    std::cin>>n;
    while(t--){
        solve();
    }
}